package com.example.smart.ui.activity

import android.annotation.SuppressLint
import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.example.lib.utils.sp.SpKey
import com.example.lib.utils.sp.SpUtils
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.databinding.ActivitySplashBinding
import com.example.smart.utils.DisplayUtils
import java.util.Timer
import kotlin.concurrent.timerTask

@SuppressLint("CustomSplashScreen")
class SplashActivity : BaseActivity<ActivitySplashBinding>() {
    private val splashTime = 300L
    private var splashScreen: SplashScreen? = null

    override fun layoutID() = R.layout.activity_splash

    override fun beforeOnCreate(savedInstanceState: Bundle?) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            splashScreen = installSplashScreen()
        }
    }

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@SplashActivity, statusBarColor = com.example.lib.R.color.translate)
        Timer().schedule(timerTask {
            runOnUiThread {
                if (SpUtils.getBoolean(SpKey.READ_GUIDE, false).not()) {
                    DisplayUtils.toGuide0(this@SplashActivity)
                } else {
                    DisplayUtils.toWelcome(this@SplashActivity)
                }
            }
        }, splashTime)
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) return true
        return super.onKeyDown(keyCode, event)
    }
}